<template>
	<view class="set-height">
		<view class="login-bigbox">
			<!-- <view class="login-top-img">
				<image class="img" src="../../static/img/img_logo_blue.png" alt="" mode="widthFix" />
			</view> -->
		</view>
		<view class="login-inpbox">
			<view class="username-box flex">
				<image class="user-img" src="../../static/icon/icon_login_user.png" alt="" mode="widthFix" />
				<input class="flex-1 input-item" v-model="mobile" type="text" placeholder="手机号码" />
			</view>
			<view class="password-box flex">
				<image class="text-img" src="../../static/icon/icon_login_mail.png" alt="" mode="widthFix" />
				<input class="flex-1 input-item" v-model="code" placeholder="短信验证码" type="number" />
				<block v-if="codeAlreadySend">
					<view class="get-code" v-if="seconds < 1" @tap="onRequestCode">重新获取</view>
					<view class="get-code" v-else>剩余{{seconds}}秒</view>
				</block>
				<block v-else>
					<view class="get-code" @tap="onRequestCode">获取验证码</view>
				</block>
			</view>
			<view class="password-box flex">
				<image class="pass-img" src="../../static/icon/icon_login_lock.png" alt="" mode="widthFix" />
				<input class="flex-1 input-item" v-model="password" placeholder="请输入密码" type="password" />
			</view>
			<view class="read-text">注册代表您已阅读并同意<text class="text-blue" @tap="onPressToNavigate()">《人才库注册使用协议》</text></view>
		</view>
		<view class="posit">
			<view class="affirm" @tap="onSubmit">立即注册</view>
			<view class="other-btn-wrap flex rcb">
				<view class="other-btn-item" />
				<view class="other-btn-item" @tap="onPressToNavigate('back')">已有账号？立即登录</view>
			</view>
		</view>

		<view class="bottom-imgbox">
			<!-- <image class="btm-img" src="../../static/img/img_bg_login_bottom.png" alt="" mode="widthFix" /> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				code: '',
				mobile: '',
				password: '',
				seconds: '',
				codeAlreadySend: false,
			}
		},
		onLoad() {
			
		},
		methods: {
			onPressToNavigate(type) {
				if(type === 'back') {
					uni.navigateBack();
				} else {
					uni.navigateTo({
						url: '/pages/login/protocol'
					});
				}
			},
			countDownTimer() {
				this.seconds = 60;
				this.codeAlreadySend = true;
				this.timerInterval = setInterval(() => {
					if (this.seconds === 0) {
						return clearInterval(this.timerInterval);
					}
					this.seconds--;
				}, 1000);
			},
			async onRequestCode() {
				// this.countDownTimer();
				// return;
				let url = this.ServicesApi.sendSMS;
				let data = {
					mobile: this.mobile,
					type: this.Constants.CODE_TYPE_REGISTER,
				}
				if(!this.mobile) {
					uni.showToast({
						icon: 'none',
						title: '请输入手机号',
					});
					return;
				}
				let result = await this.Services.post(url, data);
				uni.showToast({
					icon: 'none',
					title: result.msg,
				});
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					this.countDownTimer();
				}
			},
			async onSubmit() {
				let url = this.ServicesApi.register;
				let data = {
					code: this.code,
					mobile: this.mobile,
					password: this.password,
				}
				if(!this.mobile) {
					uni.showToast({
						icon: 'none',
						title: '请输入手机号',
					});
					return;
				}
				if(!this.code) {
					uni.showToast({
						icon: 'none',
						title: '请输入验证码',
					});
					return;
				}
				if(!this.password) {
					uni.showToast({
						icon: 'none',
						title: '请输入密码',
					});
					return;
				}
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					uni.showToast({
						title: result.msg || '注册成功',
					});
					this.timer1 = setTimeout(() => uni.navigateBack(), 1000);
				} else {
					uni.showToast({
						icon: 'none',
						title: result.msg,
					})
				}
			}
		}
	}
</script>

<style scoped lang="stylus">
	.set-height {
		// height:100vh;
		// width:100%;
		background: #fff;
		display: flex;
		flex-direction: column;
		height: 100%;
		width: 100%;
		position: absolute;
		top: 0px;
		bottom: 0px;
		background-image: url('~@/static/img/img_bg_login_bottom.png');
		background-size: 100% auto;
		background-repeat: no-repeat;
		background-position: bottom;
	}

	.input-item {
		text-indent: .725rem;
	}

	.login-bigbox {
		padding-top: 220rpx;
		background-image: url('~@/static/img/img_bg_login_top.png');
		background-position: right top;
		background-repeat: no-repeat;
		background-size: auto 220rpx;
		background-color: #FFFFFF;

		.login-top-img {
			height: 84upx;
			width: 344upx;
			margin: 0 auto;

			.img {
				height: 84upx;
				width: 344upx;
			}
		}
	}

	.login-inpbox {
		padding: 0 40rpx;
		background: #fff;

		.username-box {
			height: 60upx;
			border-bottom: 2upx solid #DBDBDB;
			margin: 30upx 0;

			.user-img {
				height: 44upx;
				width: 38upx;
				margin-right: 20upx;
			}
		}

		.password-box {
			height: 60upx;
			margin: 30upx 0;
			border-bottom: 2upx solid #DBDBDB;
			align-items center;

			.get-code {
				font-size: 30upx;
				font-weight: 400;
				color: rgba(2, 108, 232, 1);
				border-left: 1upx solid #DBDBDB;
				padding-left: 32upx;
				margin-left: 80upx;
			}

			.text-img {
				height: 30upx;
				width: 36upx;
				margin-right: 20upx;
			}

			.pass-img {
				height: 44upx;
				width: 38upx;
				margin-right: 20upx;
			}
		}
	}

	.read-text {
		font-size: 28upx;
		font-weight: 400;
		color: rgba(155, 155, 155, 1);

		.text-blue {
			color: #066FE9;
		}
	}

	.res {
		font-size: 36upx;
		color: #066FE9;
		text-align center;
		margin: 30upx auto;
		position: absolute;
		top: 0;
		left: 0;
		bottom: 0;
		right: 0;
		z-index: 100
	}

	.posit {
		position: relative;
	}

	.affirm {
		height: 90upx;
		background: linear-gradient(270deg, rgba(0, 106, 231, 1) 0%, rgba(66, 157, 255, 1) 100%);
		text-align: center;
		line-height: 90upx;
		color: #fff;
		font-size: 32upx;
		border-radius: 4upx;
		margin: 80rpx 40rpx 30rpx;
	}

	.other-btn-item {
		color: #333333;
		margin: 0 40rpx;
	}

	.bottom-imgbox {
		flex: 1;
		height: 420rpx;
		display: flex;
		align-items: flex-end;

		.btm-img {
			width: 100%;
			height: 420rpx;
		}
	}
</style>
